'''
    @Author:webrainer
    @Date:today
    @Version:
    @Since:python3.11
    @See:advisor_controller
    @Description:gpt模块，实现了   基本功能
    @Functions:
'''

import openai

openai.api_key="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"

#处理结果
'''
    @:param result:openai返回的结果，使用turbo模型
    @:return:处理后的结果，包括
    
'''


def ask(question:str,risk:str,rate:str,cost:str,time:str):
    chat=openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "You are an assistant to help me investigate."},
            {"role": "system", "content": "I am an AI investigator. I will tell you how you can buy funds."},
            {"role": "user", "content": "I want to buy a fund."},
            {"role": "user", "content": "请专注于中国市场"},
            {"role": "user", "content": "我具有"+risk+"以及"+rate+"。"+time+cost+question},
        ],

        stop=["Human"],
        max_tokens=800,
        temperature=0.9,
        top_p=1,
        frequency_penalty=0,
    )

    #去掉换行符

    return chat.choices[0].message.content


if __name__=="__main__":
    ask("我想买基金","中等风险","中等收益","中等成本","中期投资")